using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.core;
namespace TVSBH.func
{
	public class frmSelectObjectIn : Form
	{
		private IContainer components = null;
		private DataGridView dgvProduct;
		private Button btnClose;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column3;
		private DataGridViewTextBoxColumn Column1;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private Bill objBill = new Bill();
		private Partner objPartner = new Partner();
		public string TypeObject = "";
		public string objectID = "";
		public string objectName = "";
		public string strConnection = "";
		public string objectValue = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmSelectObjectIn));
			this.dgvProduct = new DataGridView();
			this.btnClose = new Button();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.Column1 = new DataGridViewTextBoxColumn();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			base.SuspendLayout();
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column7,
				this.Column2,
				this.Column3,
				this.Column1
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 8);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(583, 550);
			this.dgvProduct.TabIndex = 3;
			this.dgvProduct.CellDoubleClick += new DataGridViewCellEventHandler(this.dgvProduct_CellDoubleClick);
			this.dgvProduct.CellClick += new DataGridViewCellEventHandler(this.dgvProduct_CellClick);
			this.btnClose.Location = new System.Drawing.Point(498, 568);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(109, 28);
			this.btnClose.TabIndex = 44;
			this.btnClose.Text = "Thoát (ESC)";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column7.DataPropertyName = "Name";
			dataGridViewCellStyle.Format = "D";
			dataGridViewCellStyle.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle;
			this.Column7.HeaderText = "Đối tượng";
			this.Column7.MinimumWidth = 250;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.Width = 250;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "Address";
			this.Column2.HeaderText = "Địa chỉ";
			this.Column2.MinimumWidth = 200;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column3.DataPropertyName = "Money";
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle2.ForeColor = Color.Red;
			dataGridViewCellStyle2.Format = "N2";
			dataGridViewCellStyle2.NullValue = "0";
			this.Column3.DefaultCellStyle = dataGridViewCellStyle2;
			this.Column3.HeaderText = "Công nợ";
			this.Column3.MinimumWidth = 120;
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.Column3.Width = 120;
			this.Column1.DataPropertyName = "ID";
			this.Column1.HeaderText = "ObjectID";
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.Column1.Visible = false;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(597, 566);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(613, 600);
			this.MinimumSize = new Size(613, 600);
			base.Name = "frmSelectObjectIn";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: CHỌN ĐỐI TƯỢNG";
			base.Load += new EventHandler(this.frmDebtNeedIn_Load);
			base.KeyDown += new KeyEventHandler(this.frmDebtNeedIn_KeyDown);
			((ISupportInitialize)this.dgvProduct).EndInit();
			base.ResumeLayout(false);
		}
		public frmSelectObjectIn()
		{
			this.InitializeComponent();
		}
		private void frmDebtNeedIn_Load(object sender, EventArgs e)
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			this.getData();
		}
		private void getData()
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("Name", typeof(string));
			DataColumn column2 = new DataColumn("Address", typeof(string));
			DataColumn column3 = new DataColumn("Money", typeof(string));
			DataColumn column4 = new DataColumn("ID", typeof(string));
			dataTable.Columns.Add(column);
			dataTable.Columns.Add(column2);
			dataTable.Columns.Add(column3);
			dataTable.Columns.Add(column4);
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlCommand sqlCommand = sqlConnection.CreateCommand();
			if (this.TypeObject == "IN")
			{
				sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [IsCustomer] = 1 ORDER BY [Name]";
			}
			else
			{
				sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [IsProvider] = 1 ORDER BY [Name]";
			}
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			double num = 0.0;
			while (sqlDataReader.Read())
			{
				if (this.TypeObject == "IN")
				{
					double num2 = this.objPartner.getFistBalanceCustomer(sqlDataReader["CusID"].ToString()) + this.objPartner.getTotalMoney(sqlDataReader["CusID"].ToString()) - this.objPartner.getTotalMoneyPayedCustomer(sqlDataReader["CusID"].ToString());
					num += num2;
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Name"].ToString(),
						sqlDataReader["Address"].ToString(),
						string.Format(Program.lenAffterDecimal, num2),
						sqlDataReader["CusID"].ToString()
					});
				}
				else
				{
					double num2 = this.objPartner.getFistBalanceProvider(sqlDataReader["CusID"].ToString()) + this.objPartner.getTotalMoneyProvider(sqlDataReader["CusID"].ToString()) - this.objPartner.getTotalMoneyPayedProvider(sqlDataReader["CusID"].ToString());
					num += num2;
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Name"].ToString(),
						sqlDataReader["Address"].ToString(),
						string.Format(Program.lenAffterDecimal, num2),
						sqlDataReader["CusID"].ToString()
					});
				}
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
			this.objTable = dataTable;
			this.dgvProduct.DataSource = this.objTable;
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmDebtNeedIn_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		private void ckbProviderAll_CheckedChanged(object sender, EventArgs e)
		{
			this.getData();
		}
		private void dgvProduct_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			this.objectID = this.dgvProduct.Rows[e.RowIndex].Cells["Column1"].Value.ToString();
			this.objectName = this.dgvProduct.Rows[e.RowIndex].Cells["Column7"].Value.ToString();
			this.objectValue = this.dgvProduct.Rows[e.RowIndex].Cells["Column3"].Value.ToString();
		}
		private void dgvProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			base.Close();
		}
	}
}
